package com.zbkj.crmeb.user.model;

import java.math.BigDecimal;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * 用户购买会员记录表
 * </p>
 *
 * @author wuzp
 * @since 2022-05-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("eb_user_member_record")
@ApiModel(value="UserMemberRecord对象", description="用户购买会员记录表")
public class UserMemberRecord extends Model<UserMemberRecord> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "用户id")
    private Integer uid;

    @ApiModelProperty(value = "会员类型(1月卡，2年卡，3免费)")
    private Integer memberType;

    @ApiModelProperty(value = "有效天数")
    private Integer effectiveDays;

    @ApiModelProperty(value = "支付时间")
    private Date payTime;

    @ApiModelProperty(value = "生效时间")
    private Date effectTime;

    @ApiModelProperty(value = "到期时间")
    private Date expirationTime;

    @ApiModelProperty(value = "是否支付（0否 1是 2免费）")
    private Integer paid;

    @ApiModelProperty(value = "支付方式")
    private String payType;

    @ApiModelProperty(value = "支付金额")
    private BigDecimal payPrice;

    @ApiModelProperty(value = "订单号")
    private String orderNo;

    @ApiModelProperty(value = "第三方订单号")
    private String outOrderId;

    @ApiModelProperty(value = "商户id")
    private Integer merId;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "会员补充信息")
    private String feature;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @TableField(exist = false)
    private Map<String, String> featureMap;

    public Map<String, String> getFeatureMap() {
        if (this.featureMap != null && this.featureMap.size() > 0) {
            return this.featureMap;
        } else {
            Map<String, String> featureMap = new HashMap();
            if (StringUtils.isBlank(this.getFeatureString())) {
                return (Map)featureMap;
            } else {
                try {
                    featureMap = (Map) JSONObject.parseObject(this.getFeatureString(), Map.class);
                } catch (Exception var3) {
                }

                return (Map)featureMap;
            }
        }
    }

    public String getFeature(String name) {
        Map<String, String> featureMap = this.getFeatureMap();
        String value = (String)featureMap.get(name);
        return value == null ? "" : value;
    }

    public void addFeature(String name, String value) {
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) {
            this.featureMap = this.getFeatureMap();
            this.featureMap.put(name, value);
            this.resetFeature();
        }

    }

    public boolean removeFeature(String name) {
        if (StringUtils.isBlank(name)) {
            return true;
        } else {
            this.featureMap = this.getFeatureMap();
            if (this.featureMap.containsKey(name)) {
                this.featureMap.remove(name);
                this.resetFeature();
                return true;
            } else {
                return false;
            }
        }
    }

    public void addFeatureMap(Map<String, String> map) {
        if (map != null && !map.isEmpty()) {
            this.featureMap = this.getFeatureMap();
            this.featureMap.putAll(map);
            this.resetFeature();
        }

    }

    protected void resetFeature() {
        feature = JSONObject.toJSONString(getFeatureMap());
    }

    protected String getFeatureString() {
        return feature;
    }
}
